package com.yipingnai.blog.controller;

import com.yipingnai.blog.model.RespBean;
import com.yipingnai.blog.utils.FastDFSUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: jiangym
 * @Date: 2020/5/23 10:16
 */
@RestController
public class FIleController {

//    @Value("${fastdfs.nginx.host}")
//    String nginxHost;
    @PostMapping("/upload")
    public RespBean uploadImg(MultipartFile file){
        if(file == null){
            return RespBean.error("上传图片为空！");
        }
        String fileId = FastDFSUtil.upload(file);
        String url = "http://img.yipingnai.cn/" + fileId;
        if (fileId != null && fileId != "") {
            return RespBean.ok("上传成功",url);
        }
        return RespBean.error("上传失败");
    }
}
